Skip to content

Add hier config nested compliance rule feature#979

Draft
Dav-C wants to merge 6 commits intonautobot:developfrom
Dav-C:dcates-nested-compliance
Draft

Add hier config nested compliance rule feature#979
Dav-C wants to merge 6 commits intonautobot:developfrom
Dav-C:dcates-nested-compliance

Conversation

@Dav-C
Copy link
Copy Markdown

@Dav-C Dav-C commented Aug 8, 2025

Closes: #978

What's Changed

  • Added feature utilizing hier config for compliance rule matching nested configuration lines.
  • Updated Tests
  • Updated Docs

To Do

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@@ -0,0 +1,298 @@
# Hierarchical Configuration Compliance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should come up with a word that will resonate with the network engineer vs the technical implementation, such as partial match or filter configs.

Copy link
Copy Markdown
Author

@Dav-C Dav-C Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to Filtered Configuration Compliance. If that doesn't fit, let me know and I'll change it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If filtered doesn’t work for you, then how about “Advanced configuration compliance”

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My vote is Limited Configuration Compliance

Comment thread docs/user/app_feature_compliance_hierarchical.md Outdated
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task
from nornir_nautobot.exceptions import NornirNautobotException
from pydantic import TypeAdapter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a direct dependency in GC, we should consider if we want to make it one or not.

Comment thread nautobot_golden_config/nornir_plays/config_compliance.py Outdated
Comment thread docs/user/app_feature_compliance_hierarchical.md Outdated

Filtered configuration compliance requires:

1. **CLI Configuration Type**: Only `CLI` configuration types are supported for hierarchical compliance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to appropriate docs/repo here?

Comment on lines +29 to +35
### Repository Settings

The same repository settings required for standard compliance apply:

- Backup repository for storing device configurations
- Intended configuration repository
- Proper `backup_path_template` and `intended_path_template` configuration
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove.

Comment on lines +142 to +161
## Fallback Behavior for Empty Intended Configuration

In some cases, the intended configuration may not contain any elements that match the compliance rules, resulting in an empty intended configuration text. To handle this scenario, the system includes a fallback mechanism:

**Interface Fallback**: When the intended configuration text is empty, the system automatically looks for top-level interface configurations in the running configuration and uses them as the intended configuration baseline.

This fallback behavior:

1. **Triggers** when `intended_text` is empty after tag-based filtering
3. **Filters** for lines that start with "interface"
4. **Uses** these interface declarations as the intended configuration for comparison

**Example Scenario**:
- Your hierarchical rule targets specific VLAN configurations
- The intended configuration template doesn't include those VLANs
- The running configuration has interface declarations
- The system uses the interface lines from running config as the baseline

This ensures that remediation will not remove interfaces when intended configuration is empty for an interface.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this before pursuing further. My initial thought is this complicates things too much and going to be hard to meet everyone's POLA.

@jeffkala
Copy link
Copy Markdown
Contributor

jeffkala commented Sep 4, 2025

Think my biggest concern is the actual and intended views are filtered too. I fully agree a filtered compliance has tons of value, but that doesn't mean the intended/actual should be filtered as well. (IMHO). I think the below should happen.

  1. Actual should show as if the old "search" is being used. "interface" is the root/parent and it shows the entire interface section with all config.
  2. Intended ^^ same as above
  3. The actual compliance result should be filtered down to the hier_config rule definition.

@steve-hodgkiss
Copy link
Copy Markdown

I think filtered is the whole point TBH. Compliance rules as they stand today are currently filtered if you think about it from a certain point of view - you’re matching on the parent command rather than displaying the whole intended in one screen. For example my intended config can have loads of lines which don’t have a compliance rule set and the app is happy with all the rules green.

@jeffkala
Copy link
Copy Markdown
Contributor

jeffkala commented Sep 4, 2025

I think filtered is the whole point TBH. Compliance rules as they stand today are currently filtered if you think about it from a certain point of view - you’re matching on the parent command rather than displaying the whole intended in one screen. For example my intended config can have loads of lines which don’t have a compliance rule set and the app is happy with all the rules green.

I understand your viewpoint; however, it shifts many other users use cases. Many people use the other config plan types for example (intended) which pulls from the compliance result. This now means its a filtered intended config-set which isn't what most users want. I think the key components are to make this work alongside all the apps features/functionalities. Where the intended and actual are still showing "everything" that matches the root/main parent, and then the missing/extra/compliance result filtered down.

@jeffkala
Copy link
Copy Markdown
Contributor

jeffkala commented Oct 1, 2025

Current PR Does

Actual:

router bgp 100
    secret abcd

Intended:

router bgp 100
    secret defg

Compliance:

router bgp 100
    secret abcd

Follows Existing pattern

Actual:

router bgp 100
    neighbor 1.1.1.1 remote-as 200
    secret abcd
    prefix-list JEFF

Intended:

router bgp 100
    neighbor 1.1.1.1 remote-as 200
    secret defg
    prefix-list JEFF

Compliance:

router bgp 100
    secret abcd

@jeffkala
Copy link
Copy Markdown
Contributor

jeffkala commented Oct 1, 2025

@Dav-C I think internally we're thinking of showing both would be good. So either like this screenshot, or potentialy a toggle options between Full|Limited on intended and actual like the YAML|JSON toggle box. Just so the context isn't lost for users.
Screenshot 2025-10-01 at 12 46 13 PM

@mzbroch
Copy link
Copy Markdown
Contributor

mzbroch commented Oct 8, 2025

I had the opportunity to review this new feature and wanted to share some thoughts from an outside perspective:

  • It's important that we remain consistent at every step.
  • This means we should look at the solution as a whole, not just in terms of a new feature — everything should feel unified.
  • From my point of view, HIER-CLI is simply a specific type of configuration. This implies that (a) matching, (b) processing, and (c) reporting behave in a particular way once I decide that my ComplianceRule is of type HIER-CLI.
  • If we decide to introduce a header like # hier-cli, we should apply it consistently — across all types. If that's not feasible, perhaps we should reconsider whether the header is needed at all, especially if we can achieve the same clarity by introducing a new, dedicated type like "hier-cli".
  • There’s no real need to include more "intended config" for a rule than what’s being matched and reported. Here’s why:
  • We already follow a clear pattern — we match a section of the config and report that specific part. We don’t show the entire config above the matched snippet. Even when we have the full config available, we still only focus on the relevant fragment.
  • Introducing names like "Filtered configuration compliance" or "Advanced CLI Compliance" might sound overly complex or too heavy. Couldn’t we simply stick with the term HIER-CLI, which clearly conveys the context — i.e. hierarchical configs with a hierarchical processing engine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested compliance rules

5 participants